import { _decorator, Component, EventTouch, Node } from 'cc';
const { ccclass, property } = _decorator;

/**
 * 拖拽节点移动
 */
@ccclass('Drag')
export class Drag extends Component {
    start() {
        this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
    }

    protected onDestroy(): void {
        this.node.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
    }

    private onTouchMove(et: EventTouch) {
        const delta = et.getUIDelta()
        const toPosition = this.node.getPosition().add(delta.toVec3())
        this.node.setPosition(toPosition)
    }
}